id/email
password
forgot password | create account
about | help | prefs
ReadingBatcode reading practice

 

 

String OperationsSplit

prev  |  next  |  chance

Casting with (int) truncates values. int(5/2) equals 2

public static String split(String out, String word) {
    int halfway = (int) (out.length() / 2);
    return out.substring(0, halfway) + word + out.substring(halfway);
}
Function Call  Return Value
split("Hello", "World")
split("Person", "a")
split("Alpha", "Omega")
split("Rain", "boots")
split("School", "bus")
split("", "Hi")
split("Matt", "")
split("5", "8")

Experiment with this code on Gitpod.io

⬅ Back